/*
 * Binary program download and execute
 *
 *   usage >exec "Program.bin" "LoAdddress" "StartAddress"
 *
 */
#define MAIN  
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>

#include "pio.h"
#include "prottype.h"

void main(int ac,char *av[])
{
    int fh;
    long ladr,sadr;
   
    if((fh = open("PCFXPIO$",O_RDWR|O_BINARY))<0) {
	printf("cant open \'pcfxpio.sys\'\n");
	return;
    }

    pio_reset(fh);

    if(ac>1) {
	FILE *fp;
	long len;
	size_t l;

	buf.c = malloc(TMPSIZE);
	if( buf.c == NULL ) {
	    printf("malloc error\n");
	    close(fh);
	    return ;
	}

	if(ac>2) sscanf(av[2],"%lx",&ladr);
	else     ladr = 0x8000L;

	if(ac>3) sscanf(av[3],"%lx",&sadr);
	else     sadr = ladr;
    
	printf("Program loading ");
	myank(fh,ladr,av[1]);

	fclose(fp);

      retry:
	printf("Exec %lx\n",sadr);
	pio_run(fh,sadr);                       /* Program Start */
    } else {
	printf("usage >exec \"Program.bin\" \"LoadAddress\" \"StartAddress\"\n");
    }

    close(fh);
}

/* EOF */
